home *** CD-ROM | disk | FTP | other *** search
- /*
- CDStopTrack - An XCMD to stop play at the end of a specific track.
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/10/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDStopTrack.c
- link -sn Main=CDStopTrack -sn STDIO=CDStopTrack ∂
- -sn INTENV=CDStopTrack -rt XFCN=42 ∂
- -m CDStopTrack CDStopTrack.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- void ExtractTrackNo(char *, short *);
- OSErr AStop(short, short);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDStopTrack
- *
- * Purpose: stop playing at the end of an audio track
- *
- * Returns: result of driver call to stop track
- * normally 0, but could have parameter error or
- * other error if non-existent track is specified
- *
- * Side Effects:
- *
- * Description: We need one parameters. Get the ioRefNum that we got
- * from previously calling CDOpen() via a famous
- * global. Get the track
- * number. Extract the track number and issue a stop.
- * To play only one track, you issue a stop for that
- * track, followed by a play for that track.
- *
- ************************************************************************/
- pascal void
- CDStopTrack(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short trackNumber;
- short ioRefNum;
- Handle refHandle;
-
- /* Must be one parameter */
- if ((paramPtr->paramCount) != 1)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- /* First param is track number. Convert it to a pascal string */
- ExtractTrackNo((char *)*(paramPtr->params[0]), &trackNumber);
-
- result = AStop(trackNumber, ioRefNum);
-
- /* Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
-
- /************************************************************************
- *
- * Function: ExtractTrackNo
- *
- * Purpose: Extract track number in BCD from PString
- *
- * Returns: nothing
- *
- * Side Effects: *track gets a new value
- *
- * Description: Extract track number in BCD from Cstring "name".
- * "name" is always of the form "XX", where XX
- * ranges from "1" to "99"
- * (You can't have more than 99 tracks on a compact disc.
- * Bet you didn't know that, did you? Right in the "Yellow
- * Book" specification of compact disc encoding.)
- *
- ************************************************************************/
- void
- ExtractTrackNo(name, track)
- char *name;
- short *track;
- {
- short t;
-
- t = 0;
- while (*name != 0)
- {
- t *= 16;
- t += *name - '0';
- name++;
- }
-
- *track = t;
- }
-
- /************************************************************************
- *
- * Function: AStop
- *
- * Purpose: stop playing an audio track
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: stops play.
- *
- * Description: The track that you pass in is the LAST track that you
- * want to have play. This means that if you wanted to
- * play only one track, you'd pass the same value to
- * this routine and APlay() [q.v.]
- *
- * Note that this routine isn't called in this sample,
- * but it's included for your enjoyment.
- *
- ************************************************************************/
- OSErr
- AStop(track, refNum)
- short track;
- short refNum;
- {
- struct {
- short addrFormat;
- long address;
- } csParam;
-
- csParam.addrFormat = TRACKADDR;
- csParam.address = track;
- return (Control(refNum, ASTOP, &csParam));
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-